﻿@model IEnumerable<Seven.DataModel.ViewModels.DeskModuleAbout.UserDeskModuleModel>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutForDesk.cshtml";

    var left = Model.Where(w => w.Location == Seven.EntityBasic.DeskModuleLocation.左边);
    var right = Model.Where(w => w.Location == Seven.EntityBasic.DeskModuleLocation.右边);
}
<script src="~/Scripts/views/Desk/desk.js"></script>
<div id="deskPanel" class="easyui-panel" data-options="fit:true,border:false,bodyCls:'BigIframe'">
    <div id="portal" class="easyui-portal" data-options="fit: true, border: false">
        @if (Model.Count() > 0)
        {
            if (left.Count() > 0 && right.Count() > 0)
            {
        <div style="width: 55%;">
            @foreach (var item in left)
                    {
            <div id="deskModule_@(item.DeskModuleID)" data-options="title:'@(item.DeskModuleName)',height:'@(item.Height)',href:'@(item.Url)'">
            </div>
                    }
        </div>
        <div style="width: 45%;">
            @foreach (var item in right)
                    {
            <div id="deskModule_@(item.DeskModuleID)" data-options="title:'@(item.DeskModuleName)',height:'@(item.Height)',href:'@(item.Url)'">
            </div>
                    }
        </div>
            }
            else
            {
                if (left.Count() > 0)
                {
        <div style="width:100%;">
            @foreach (var item in left)
                        {
            <div id="deskModule_@(item.DeskModuleID)" data-options="title:'@(item.DeskModuleName)',height:'@(item.Height)',href:'@(item.Url)'">
            </div>
                        }
        </div>
                }
                else if (right.Count() > 0)
                {
        <div style="width:100%;">
            @foreach (var item in right)
                        {
            <div id="deskModule_@(item.DeskModuleID)" data-options="title:'@(item.DeskModuleName)',height:'@(item.Height)',href:'@(item.Url)'">
            </div>
                        }
        </div>
                }
            }
        }
        else
        {
        <div style="width:100%;">
            <div data-options="title:'欢迎使用Seven!',height:400">
                那是再也回不去的年少时光，以及早已不知所踪的骄傲的自己。
            </div>
        </div>
        }
    </div>
</div>
<script>
    $(function () {
        var portal1 = $("#portal"), table1 = portal1.find("table:first"),
            portalHeight = portal1.height(), portalWidth = portal1.width(),
            tds = table1.find("td.portal-column-td"),
            portalTableHeight = table1.height(), portalTableWidth = table1.width();
        var targetTd; var tempLen = 0;
        tds.each(function (i, td) {
            var len = $(td).children("div:first").children("div.portal-panel").length;
            if (len > tempLen) { tempLen = len; targetTd = $(td); }
        });

        if (portalTableHeight > portalHeight) {
            portal1.portal("resize", { width: portalWidth - 20 });
        }
    });
</script>